package cn.edu.nuaa.codemetric.controller;

import cn.edu.nuaa.codemetric.service.MetricService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import java.util.concurrent.TimeUnit;

@Controller
public class MetricController {

    @Autowired
    private MetricService metricService;

    @PostMapping("/codeMetric")
    @ResponseBody
    public String codeMetric(@RequestBody String raw) throws Exception {
        //拆出语言类型、代码
        JSONObject input = JSONObject.parseObject(raw);
        String language=input.getString("lang");
        String code=input.getString("code");
        System.out.println(language);
        System.out.println(code);
        return metricService.getCodeMetric(language,code);
    }
}
